package com.qolome.knowledge.design.pattern.adapter.demo.passport.adapters;


import com.qolome.knowledge.design.pattern.adapter.demo.passport.PassportService;
import com.qolome.knowledge.design.pattern.adapter.demo.passport.ResultMsg;


public abstract class AbstractAdapter  implements ILoginAdapter {

    protected PassportService passportService;

    protected AbstractAdapter(PassportService passportService) {
        this.passportService = passportService;
    }

    protected ResultMsg loginForResist(String username, String password) {
        if(null == password){
            password = "THIRD_EMPTY";
        }
        dealWithLoginLogic(username);
        passportService.regist(username, password);
        return passportService.login(username, password);
    }
    @Override
    public ResultMsg login(String id, Object adapter) {
        if(!support(adapter)) {
            throw new IllegalArgumentException("参数错误");
        }
        return loginForResist(id, null);
    }

    /**
     * @Author 钩子方法
     * @Description //钩子方法
     * @Date 2020/3/11 11:27
     * @param id
     * @return void
     **/
    protected abstract void dealWithLoginLogic(String id);

}
